package com.controller;


import com.domain.Goods;
import com.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private IGoodsService IgoodsService;

    @GetMapping("/findGoods")
    public List<Goods> doFindGoods(Model model) {
        return IgoodsService.findGoods();
    }

    @GetMapping("/deleteById/{id}")
    public String doDeleteById(@PathVariable Integer id){
        return "删除成功啦--->" + IgoodsService.deleteById(id);
    }

    @RequestMapping("/saveGoods")
    public String doSaveGoods(@RequestBody Goods goods){
        return "添加成功啦--->" + IgoodsService.insertObject(goods);
    }

    @RequestMapping("/findById/{id}")
    public Goods doFindById(@PathVariable Integer id){
        return IgoodsService.selectOne(id);
    }

    @RequestMapping("/updateGoods")
    public String doUpdateGoods(@RequestBody Goods goods){
        return "修改成功啦--->" + IgoodsService.updateGoods(goods);
    }
}
